package cn.cscamp.middleware.loadbalancer.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@ConfigurationProperties(prefix = "loadbalancer")
public class LoadbalancerServiceConfig {

    private Map<String, List<String>> services;

    public Map<String, List<String>> getServices() {
        return services;
    }

    public void setServices(Map<String, List<String>> services) {
        this.services = services;
    }

    public List<LoadbalancerService> getLoadbalancerServices() {
        return services.entrySet().stream()
                .map(entry -> new LoadbalancerService(entry.getKey(), entry.getValue()))
                .collect(Collectors.toList());
    }
}
